FogSettings.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using ExternPropertyAttributes;
  3. using UnityEngine;
  4. using UnityEngine.Rendering.Universal;
  5. // ReSharper disable RedundantDefaultMemberInitializer
  6. #if UNITY_2022_3_OR_NEWER
  7. namespace FlatKit {
  8. [CreateAssetMenu(fileName = "FogSettings", menuName = "FlatKit/Fog Settings")]
  9. public class FogSettings : ScriptableObject {
  10. [Space] // Expandable.
  11. [Label("<b>Distance Fog</b>")]
  12. [Tooltip("Whether to use distance fog. This is the fog that fades out the scene into the background.")]
  13. public bool useDistance = true;
  14. [Tooltip("The color changes from near (left) to far (right).")]
  15. [Label(" Distance Gradient"), ShowIf(nameof(useDistance))]
  16. public Gradient distanceGradient;
  17. [Tooltip("The distance from the camera in world units at which the fog starts.")]
  18. [Label(" Near"), ShowIf(nameof(useDistance))]
  19. public float near = 0;
  20. [Tooltip("The distance from the camera in world units at which the fog ends.")]
  21. [Label(" Far"), ShowIf(nameof(useDistance))]
  22. public float far = 100;
  23. [Range(0, 1)]
  24. [Tooltip("How much the fog should be applied. 0 means no fog, 1 means full fog.")]
  25. [Label(" Intensity"), ShowIf(nameof(useDistance))]
  26. public float distanceFogIntensity = 1.0f;
  27. [Space(12)]
  28. [HorizontalLine(1, EColor.Translucent)]
  29. [Label("<b>Height Fog</b>")]
  30. [Tooltip("Whether to use height fog. This is the fog that goes up from the ground.")]
  31. public bool useHeight = false;
  32. [Tooltip("The color changes from low (left) to high (right).")]
  33. [Label(" Height Gradient"), ShowIf(nameof(useHeight))]
  34. public Gradient heightGradient;
  35. [Tooltip("The height in world units at which the fog starts.")]
  36. [Label(" Low"), ShowIf(nameof(useHeight))]
  37. public float low = 0;
  38. [Tooltip("The height in world units at which the fog ends.")]
  39. [Label(" High"), ShowIf(nameof(useHeight))]
  40. public float high = 10;
  41. [Range(0, 1)]
  42. [Tooltip("How much the fog should be applied. 0 means no fog, 1 means full fog.")]
  43. [Label(" Intensity"), ShowIf(nameof(useHeight))]
  44. public float heightFogIntensity = 1.0f;
  45. [Tooltip("Reverts fog behavior to pre-3.9.0. This is useful if you want to use the new fog settings, but want to " +
  46. "keep the old look of your scene.")]
  47. [Label(" Camera Relative Position"), ShowIf(nameof(useHeight))]
  48. public bool cameraRelativePosition = false;
  49. [Space(12)]
  50. [HorizontalLine]
  51. [Header("Blending")]
  52. [Range(0, 1)]
  53. [Tooltip("The ratio between distance and height fog. 0 means only distance fog, 1 means only height fog.")]
  54. [Label(" Distance/Height Blend")]
  55. public float distanceHeightBlend = 0.5f;
  56. [Header("Advanced Settings")]
  57. [Tooltip("The render stage at which the effect is applied. To exclude transparent objects, like water or " +
  58. "UI elements, set this to \"Before Transparent\".")]
  59. [Label(" Render Event")]
  60. public RenderPassEvent renderEvent = RenderPassEvent.BeforeRenderingPostProcessing;
  61. [Tooltip("Whether the effect should be applied in the Scene view as well as in the Game view. Please keep in " +
  62. "mind that Unity always renders the scene view with the default Renderer settings of the URP config.")]
  63. [Label(" Apply In Scene View")]
  64. public bool applyInSceneView = true;
  65. [HideInInspector]
  66. public Material effectMaterial;
  67. internal Action onSettingsChanged;
  68. internal Action onReset;
  69. private void OnValidate() {
  70. low = Mathf.Min(low, high);
  71. high = Mathf.Max(low, high);
  72. onSettingsChanged?.Invoke();
  73. }
  74. private void Reset() {
  75. onReset?.Invoke();
  76. }
  77. private void OnDestroy() {
  78. onSettingsChanged = null;
  79. onReset = null;
  80. }
  81. }
  82. }
  83. #else
  84. namespace FlatKit {
  85. [CreateAssetMenu(fileName = "FogSettings", menuName = "FlatKit/Fog Settings")]
  86. public class FogSettings : ScriptableObject {
  87. [Header("Distance Fog")]
  88. public bool useDistance = true;
  89. public Gradient distanceGradient;
  90. public float near = 0;
  91. public float far = 100;
  92. [Range(0, 1)]
  93. public float distanceFogIntensity = 1.0f;
  94. public bool useDistanceFogOnSky = false;
  95. [Header("Height Fog")]
  96. [Space]
  97. public bool useHeight = false;
  98. public Gradient heightGradient;
  99. public float low = 0;
  100. public float high = 10;
  101. [Range(0, 1)]
  102. public float heightFogIntensity = 1.0f;
  103. public bool useHeightFogOnSky = false;
  104. [Header("Blending")]
  105. [Space]
  106. [Range(0, 1)]
  107. public float distanceHeightBlend = 0.5f;
  108. [Header("Advanced settings")]
  109. [Space, Tooltip("The render stage at which the effect is applied. To exclude transparent objects, like water or " +
  110. "UI elements, set this to \"Before Transparent\".")]
  111. public RenderPassEvent renderEvent = RenderPassEvent.BeforeRenderingPostProcessing;
  112. [Tooltip("Whether the effect should be applied in the Scene view as well as in the Game view. Please keep in " +
  113. "mind that Unity always renders the scene view with the default Renderer settings of the URP config.")]
  114. public bool applyInSceneView = true;
  115. private void OnValidate() {
  116. low = Mathf.Min(low, high);
  117. high = Mathf.Max(low, high);
  118. }
  119. }
  120. }
  121. #endif